package com.polaris.live.adapter

import android.text.TextUtils
import android.view.View
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.StringUtils.getString
import com.blankj.utilcode.util.TimeUtils
import com.polaris.live.R
import com.polaris.live.common.R.color
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.ext.dp
import com.polaris.live.databinding.AdapterInfoUserBinding
import com.polaris.live.resp.bean.InfoUserBean
import com.polaris.live.translation.R.string
import com.polaris.live.ui.user.InfoUserActivity
import com.polaris.live.utils.CommonUtils

/**
 * InfoUserAdapter
 *
 * @author Created by 半仙 on 2023/9/23/023 14:52
 */
class InfoUserAdapter : BaseBindingAdapter<AdapterInfoUserBinding, InfoUserBean>() {

    override fun convert(holder: VBViewHolder<AdapterInfoUserBinding>, item: InfoUserBean) {
        holder.vb.apply {
            infoKeyText.text = item.key

            if (!TextUtils.isEmpty(item.value) && item.perfect == InfoUserActivity.PERFECT) {
                infoValueText.text = item.value
            }
            //这里的2就默认是生日了  如果后面改动一定要注意这里哈
            if (holder.absoluteAdapterPosition == 2) {
                item.value?.toLongOrNull()?.let {
                    infoValueText.text = TimeUtils.millis2String(it, "yyyy-MM-dd")
                }
            } else if (holder.absoluteAdapterPosition == 4) {
                infoValueText.text = item.value?.let { CommonUtils.getLanguageNameFromCode(it) }
            } else if (holder.absoluteAdapterPosition == 3) {
                val sex = item.value?.toInt()
                if (sex != null) {
                    if (CommonUtils.isMan(sex)) {
                        infoValueText.text = getString(string.man)
                    } else {
                        infoValueText.text = getString(string.woman)
                    }
                }
            } else if (holder.absoluteAdapterPosition == data.size - 1) {
                infoValueText.text = item.value?.let { CommonUtils.getCountryName(it) }
            }

            if (!TextUtils.isEmpty(item.keyDown)) {
                val layout = llItem.layoutParams
                layout.height = 74.dp
                llItem.layoutParams = layout
                infoKeyDown.text = item.keyDown
                infoKeyDown.visibility = View.VISIBLE
            } else {
                val layout = llItem.layoutParams
                layout.height = 56.dp
                llItem.layoutParams = layout
                infoKeyDown.visibility = View.GONE
            }

            if (item.type == InfoUserActivity.INFO) {
                infoIsInfoImg.visibility = View.VISIBLE
                if (item.perfect == InfoUserActivity.PERFECT) {
                    infoValueText.setTextColor(ColorUtils.getColor(color.color_202028))
                } else {
                    infoValueText.text = context.getString(string.no_perfect)
                    infoValueText.setTextColor(ColorUtils.getColor(color.color_fe1849))
                }
            } else {
                infoIsInfoImg.visibility = View.GONE
                infoValueText.setTextColor(ColorUtils.getColor(R.color.a7a8ad))
            }

            if (TextUtils.isEmpty(item.url)) {
                infoCountryImg.visibility = View.GONE
            } else {
                infoCountryImg.visibility = View.VISIBLE
            }
        }
    }

}